package com.woniuxy.patrol.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.patrol.dto.PatrolStatsDTO;
import com.woniuxy.patrol.pojo.PatrolPointRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
* @author 13162
* @description 针对表【wcm_patrol_point_record(点位巡更记录表)】的数据库操作Mapper
* @createDate 2025-07-14 19:36:56
* @Entity com.woniuxy.patrol.pojo.PatrolPointRecord
*/
public interface PatrolPointRecordMapper extends BaseMapper<PatrolPointRecord> {

    /**
     * 根据任务ID查询巡更记录
     */
    List<PatrolPointRecord> selectByTaskId(@Param("taskId") Long taskId);

    /**
     * 根据点位ID查询历史记录
     */
    List<PatrolPointRecord> selectByPointId(@Param("pointId") Long pointId);

    Page<PatrolPointRecord> selectByCommunity(
            Page<PatrolPointRecord> page,
            @Param("communityId") Long communityId,
            @Param("startTime") String startTime,
            @Param("endTime") String endTime
    );

    // 新增：查询统计数据
    PatrolStatsDTO selectPatrolStats(@Param("communityId") Long communityId);

    // 新增：查询最近异常记录
    Page<PatrolPointRecord> selectRecentExceptions(
            Page<PatrolPointRecord> page,
            @Param("communityId") Long communityId,
            @Param("limit") Integer limit
    );
    // 新增：通过社区ID关联查询巡更记录
    List<PatrolPointRecord> selectByCommunityWithPoint(
            @Param("communityId") Long communityId,
            @Param("startTime") String startTime,
            @Param("endTime") String endTime);

    @MapKey("communityId")
    List<Map<String, Object>> selectExceptionTypeDistribution(Long communityId);

    // 新增：统计不重复的已签到点位数量
    long countDistinctCompletedPoints(@Param("taskId") Long taskId);
}




